<template>
  <div class="page-city-news-detail">
    <div style="margin-bottom: 20px;display: flex">
      <a href="/" style="font-size: 12px;color: #999999;text-decoration: none;">首页</a>
      <span style="font-size: 12px;padding: 0 5px;color: #999999;font-family: 'PingFang SC'">·</span>
      <a href="/" style="font-size: 12px;color: #999999;text-decoration: none;">租车</a>
      <span style="padding: 0 5px;color: #999999;font-family: 'PingFang SC'">·</span>
      <a href="/" style="font-size: 12px;color: #999999;text-decoration: none;">租车资讯</a>
    </div>
    <div class="news-main">

      <!-- 资讯详情左边     -->
      <div class="main" style="position: relative">
        <div style="width: 644px;height: 100%">
          <h1 style="font-size: 20px;font-weight: 700;padding: 20px 30px 15px;">{{newInfoList.title}}</h1>
          <time style="padding: 0 30px;font-size: 12px;color: #999;">{{newInfoList.createdTime}} </time>
          <div class="tag-list" style="padding: 0 30px;margin-top: 20px;display: flex;">
            <router-link :to="'/searchBy/categoryId/' + newInfoList.categoryId" style="text-decoration: none;">
              {{newInfoList.categoryName}}
            </router-link>
          </div>
          <div v-html="newInfoList.content" style="font-size:16px;padding: 20px 30px 15px;"></div>
      </div>

        <div style="width: 100%; border: 1px solid rgb(237, 237, 237)"></div>


      </div>
      <!-- 专题页右边     -->
      <div class="aside">
        <div class="com-news-panel" style="width: 400px">
          <header>
            <h2 style="font-size: 20px;font-weight: 700">
              最新文章
              <img style="width: 30px" src="">
            </h2>
          </header>
          <div class="list">
            <router-link :to="'/newsDetail/' + item.id"  class="news-item article-item" v-for="item in news" style="text-decoration: none">
              {{item.title}}
            </router-link>
          </div>
        </div>
        <div class="com-news-panel" style="width: 400px">
          <header>
            <h2 style="font-size: 20px;font-weight: 700">
              热点文章
              <img style="width: 30px" src="">
            </h2>
          </header>
          <div class="list">
            <router-link :to="'/newsDetail/' + item.id"  class="news-item article-item" v-for="item in HotNews" style="text-decoration: none">
              {{item.title}}
            </router-link>
          </div>
        </div>

      </div>
    </div>
    <div style="margin-bottom: 40px;">
      <h1 class="qjx-left-component-sub-title">同价位车型推荐</h1>
      <el-row :gutter="10">
        <el-col :span="6" v-for="item in 4">
          <a href="#" >
            <img class="qjx_image" style="transition: all 0.2s ease-in-out; width: 100%; border-radius: 5px;" src="https://carphoto.atzuche.com/car/22/12/38473345/1670316060671_1.jpg?x-oss-process=image/resize,m_lfit,h_315,w_480">
          </a>
          <p style="text-align: left; font-size: 12px;">
            <a href="#" class="qjx-recommend-car-link" style="text-decoration: none; color: #333;"><strong style="font-size: 15px">蔚来 EC6 电动车 自动挡</strong></a><br>
            <span >沪A****61 <span style="color: #ff5c5c">4.0分</span></span><br>
            <span style=" display: block; margin-top: 15px; color: #ff5c5c"><strong style="font-size: 18px;">5970元</strong>/月均</span>

          </p>
        </el-col>
      </el-row>
    </div>

  </div>


</template>

<script setup>

import { onMounted, ref} from "vue";
import request from '@/utils/request';
import {ElMessage} from "element-plus";
import {onBeforeRouteUpdate, useRoute} from "vue-router";


//资讯详情------------------------------
const newInfoList = ref({});

//24小时文章
const news = ref([]);

//热点文章
const HotNews = ref([]);

let id = null;

//详情页刷新
const newsDetail = ()=> {
  request.get('/v1/news/byNewsId/' + id)
      .then((response) => {
        if (response.code == 200) {
          newInfoList.value = response.data;
        } else {
          ElMessage.error(response.data.msg);
        }
      })
  getNews();
  getHotNews();
}

//24小时文章------------------------------------------
const getNews = () => {
  let url = `/v1/news/latestNews`;
  request.get(url).then((response) => {
    if (response.code === 200) {
      console.log(response.data);
      news.value = response.data;
    } else {
      ElMessage.error(response.data.msg);
    }
  })
};

//热点文章-----------------------------------------
const getHotNews = () => {
  let url = `/v1/news/hot`;
  request.get(url).then((response) => {
    if (response.code === 200) {
      console.log(response.data);
      HotNews.value = response.data;
    } else {
      ElMessage.error(response.data.msg);
    }
  })
};

//页面跳转过来立即执行 A-->B
onMounted(()=>{
  id= useRoute().params.id;
  newsDetail();
})
//从本页面跳到本页面路由切换初始化数据
onBeforeRouteUpdate((to, from, next) => {
  id= to.params.id
  newsDetail();
  next();
});
</script>


<style scoped>
.qjx-left-component-sub-title{
  font-weight: bold;
  font-size: 20px;
  text-align: left;
  margin-bottom: 20px;

}
.page-city-news-detail {
  width: 1024px;
  margin: 0 auto;
  padding-top: 25px;
  padding-bottom: 40px;
}
.page-city-news-detail .news-main {
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: start;
  align-items: flex-start;
  margin-bottom: 40px;
}
.main .tag-list>a {
  border-radius: 2px;
  margin-right: 5px;
  display: -ms-flexbox;
  display: flex;height: 26px;
  line-height: 26px;
  color: #3c3c5a;
  font-size: 12px;
  padding: 0 8px;
  overflow: hidden;
  background: rgba(60, 60, 90, .05);
}
.main .content {
  overflow: hidden;
  margin-bottom: 20px;
  padding: 30px;
  min-height: 500px;
  font-size: 14px;
  line-height: 2;
}
.main .pager {
  display: flex;
  border-top: 1px solid #f5f5f5;
  padding: 15px 20px;
}
.main .pager>a {
  display: flex;
  color: #00bc93;
  font-size: 12px;
  padding: 0 10px;
  max-width: 50%;
  overflow: hidden;
}
.main .pager .next {
  margin-left: auto;
  text-align: right;
  background: url() 100% no-repeat;
  background-size: 10px;
}




.page-subject-rent {
  width: 1100px;
  padding-bottom: 40px;
  margin: 0 auto 20px;

}

.at-breadcrumb>a {
  display: block;
  color: #999;
}


.at-breadcrumb>span {
  display: block;
  padding: 0 5px;
}

.page-subject-rent .subject-main {
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: start;
  align-items: flex-start;
  margin-bottom: 40px;
}


.page-subject-rent .subject-main .main {
  -ms-flex: 1 1;
  flex: 1 1;
  width: 100%;
  margin-right: 20px;
  border: 1px solid #f5f5f5;

  border-radius: 5px;
}

.main {
  width: 1024px;
}


.page-subject-rent .subject-main .main>h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}

.page-subject-rent .subject-main .main .list {
  overflow: hidden;
  margin-right: -20px;
}


.page-subject-rent .subject-main .main .subject-item {
  width: 290px;
  float: left;
  margin: 0 20px 20px 0;
  display: block;
  -webkit-transition: all .2s ease-out;
  transition: all .2s ease-out;
  border-radius: 5px;
}


.page-subject-rent .subject-main .main .subject-item .header {
  display: block;
  position: relative;
  width: 100%;
  height: 150px;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  overflow: hidden;
}

.page-subject-rent .subject-main .main .subject-item .header img {
  display: block;
  width: 100%;
  height: 100%;
  background-color: #f0f0f0;
}

.page-subject-rent .subject-main .main .subject-item .header h3 {
  position: absolute;
  left: 15px;
  bottom: 15px;
  font-size: 17px;
  color: #fff;
  font-weight: 700;
}


.page-subject-rent .subject-main .main .subject-item .text {
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
  border: 1px solid #f5f5f5;
  border-top: none;
  padding: 15px;
}
.page-subject-rent .subject-main .main .subject-item .text p {
  font-size: 14px;
  line-height: 20px;
  height: 60px;
  overflow: hidden;
}

.page-subject-rent .subject-main .main .pagination {
  margin-top: 20px;
}



.page-subject-rent .subject-main .aside {
  width: 360px;
}

.com-news-panel {
  border: 1px solid #f5f5f5;
  padding: 20px;
  border-radius: 5px;
}

.com-news-panel header {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: center;
  align-items: center;
}
.com-news-panel header h2 {
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: center;
  align-items: center;
}

.com-news-panel header>* {
  font-weight: 700;
}

.com-news-panel .list {
  display: block;
  overflow: hidden;
}
.com-news-panel a.news-item {
  display: -ms-flexbox;
  display: flex;
  color: #666;
  font-size: 12px;
  margin-bottom: 15px;
  background: url() 0 no-repeat;
  background-size: 4px auto;
  padding-left: 10px;
}
a.news-item:hover{
  color: #00bc93;
}
.com-news-panel a.news-item:last-child {
  margin-bottom: 0;
}
.com-news-panel a.news-item .p {
  overflow: hidden;
  white-space: nowrap;
  max-width: 80%;
}
.com-news-panel a.news-item .dot {
  display: block;
  width: 100%;
  -ms-flex: 1 1;
  flex: 1 1;
  background: url() 0 repeat-x;
  background-size: 4px auto;
  margin: 0 10px;
}

.page-subject-rent .hot-cars-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}


</style>


